package leetcode.code120.Triangle;

import java.util.List;

public class Solution12002 extends Triangle {

	@Override
	public int minimumTotal(List<List<Integer>> triangle) {
		int len = triangle.size();
		int[][] arr = new int[len][len];
		int x = 0;
		int y = 0;
		for (List<Integer> l : triangle) {
			for (Integer num : l) {
				arr[x][y] = num;
				y++;
			}
			x++;
			y = 0;
		}
		return this.dp(arr, 0, 0);
	}

	public int dp(int[][] arr, int x, int y) {
		System.out.println(x + " " + y);
		if (x == arr.length - 1) {
			if (y < arr[x].length)
				return arr[x][y];
			else
				return 0;
		}
		int a = arr[x][y] + dp(arr, x + 1, y);
		int b = arr[x][y] + dp(arr, x + 1, y + 1);
		return a > b ? b : a;
	}

	public static void main(String[] args) {
		Solution12002 so = new Solution12002();
		so.debug1();
		so.debug2();
		so.debug3();
		so.debug4();
	}

}
